/**
 * 
 */
package com.planner.core.action.search;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.beans.factory.annotation.Required;

import com.planner.core.action.core.AbstractBaseAction;
import com.planner.core.action.search.form.SearchRouteForm;
import com.planner.core.dao.stub.StubUtil;
import com.planner.core.service.core.search.SearchService;
import com.planner.core.vo.GraphNode;

/**
 * @author Sangharsh
 *
 */
public class SearchRouteAction extends AbstractBaseAction {

	private static final Log LOG = LogFactory.getLog(SearchRouteAction.class);
	
	private SearchService searchService; 
	/* (non-Javadoc)
	 * @see com.planner.core.action.core.AbstractBaseAction#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		SearchRouteForm searchForm = (SearchRouteForm)form;
		setStaticData(searchForm);
		if(searchForm.getFrom() >0 && searchForm.getTo() >0){
			System.out.println(searchForm.getFrom()+":"+searchForm.getTo());
			List<GraphNode> path = searchService.getPath(searchForm.getFrom(), searchForm.getTo());
			searchForm.setPath(path);
		}
		LOG.info("Search Route");
		return mapping.findForward(SUCCESS_FORWARD);
	}
	private void setStaticData(SearchRouteForm routeForm) {
		routeForm.setTypes(StubUtil.getNodeTypes());
	}
	/**
	 * @param searchService the searchService to set
	 */
	@Required
	public void setSearchService(SearchService searchService) {
		this.searchService = searchService;
	}
	
}
